package com.example.administrator.meishi.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.example.administrator.meishi.R;
import com.example.administrator.meishi.bean.Video;

import java.util.List;

/**
 * Created by Administrator on 2016/9/22.
 */
public class PullAdapter1 extends BaseAdapter{
    private LayoutInflater mInflater;
    private List<Video> mdata;
    private Context mContext;

    public PullAdapter1(Context context) {
        this.mContext = context;
        mInflater = LayoutInflater.from(context);
    }

//    public PullAdapter1(Context context, List<Video> list) {
//
//    }

    //接受数据
    public void setData(List<Video> list) {
        this.mdata=list;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mdata != null ? mdata.size():0;
    }

    @Override
    public Object getItem(int position) {
        return mdata != null ?mdata.get(position): 0;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null){
            convertView = mInflater.inflate(R.layout.list_item,parent,false);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        }else{
            holder = (ViewHolder) convertView.getTag();
        }
        Video b = mdata.get(position);
//        String cover_pic = mei.getRecommend_cover_pic();
//        String avatar = mei.getMedia().getUser().getAvatar();
//        String caption = mei.getRecommend_caption();
        if (b.getMedia()==null){

        }else {
            //绑定数据
            holder.tv_b.setText(b.getRecommend_caption());
            Glide.with(parent.getContext()).load(b.getRecommend_cover_pic()).placeholder(R.mipmap.g).into(holder.ivg);
            Glide.with(parent.getContext()).load(b.getMedia().getUser().getAvatar()).placeholder(R.mipmap.g).into(holder.ivg1);
        }

        return convertView;
    }
    class ViewHolder{
        ImageView ivg,ivg1;
        TextView tv_t,tv_b;
        //找到控件
        public ViewHolder(View converView){
            ivg= (ImageView) converView.findViewById(R.id.ivg);
            ivg1= (ImageView) converView.findViewById(R.id.ivg1);
            tv_t= (TextView) converView.findViewById(R.id.tv_t);
            tv_b= (TextView) converView.findViewById(R.id.tv_b);
        }
    }
}
